function throttle(fn, delaySeconds) {
    let lastTime = Date.now()
    const capitalize = str => str.replace(/^\w/, m => m.toUpperCase())
    const res = {
        ['thr' + (fn.name ?  capitalize(fn.name) : 'Fn')](...args) {
            const curTime = Date.now()
            const elapsedSeconds = (curTime - lastTime) / 1000
            if (elapsedSeconds < delaySeconds) {
                return
            }
    
            lastTime = curTime
            return fn.apply(this, args)
        }
    }
    return Object.values(res).pop()
}


function hello(name) {
    console.log('hello', name)
}


const thrHello = throttle(hello, 1);

// 模拟高频执行
function highFrequencyCall(fn, args = [], msDelay = 300, maxTimes = 10) {
    let callTimes = 0
    let timer = null
    timer = setInterval(() => {
        if (callTimes >= maxTimes) {
            clearInterval(timer)
            return
        }

        callTimes++;
        console.log(callTimes, 'calling fn:', fn.name)
        fn.apply(this, args)
    }, msDelay)
}

highFrequencyCall(thrHello, ['Alice'])